/**
 * UNIVERSIDADE FEDERAL DO RIO GRANDE DO NORTE - UFRN
 * DEPARTAMENTO DE INFORMATICA E MATEMATICA APLICADA - DIMAP
 * Programa de Pos-Graduacao em Sistemas e Computacao - PPGSC
 */
package br.ufrn.spl.ev.engines.miners.iproject;

import java.util.Properties;

import br.ufrn.spl.ev.engines.miners.MinerFactory.MergeSide;
import br.ufrn.spl.ev.models.changeloghistorymodel.ChangeLog;
import br.ufrn.spl.ev.models.changeloghistorymodel.ChangeLogHistory;
import br.ufrn.spl.ev.models.changeloghistorymodel.ChangeLogType;
import br.ufrn.spl.ev.models.changeloghistorymodel.ChangeTypeRepository;
import br.ufrn.spl.ev.models.changeloghistorymodel.ClassChangeLog;
import br.ufrn.spl.ev.models.changeloghistorymodel.FeatureChangeLog;
import br.ufrn.spl.ev.models.changeloghistorymodel.FieldChangeLog;
import br.ufrn.spl.ev.models.changeloghistorymodel.MethodChangeLog;

/**
 * <p>A mock class to test IPROJECT Miner</p>
 *
 * <p>Return a change logs without consult the IPROJECT or SVN, so we can run it everywhere </p>
 *
 * @author jadson - jadson@info.ufrn.br
 * @vesion 1.0 - Class Creation.
 * @since 10/10/2013
 *
 */
public class IprojectMinerMock extends IprojectMiner {

	private MergeSide side;
	
	public IprojectMinerMock(MergeSide side) {
		this.side = side;
	}

	/**
	 * 
	 * @see br.ufrn.spl.ev.engines.miners.iproject.IprojectMiner#performMining(java.util.Properties)
	 */
	@Override
	public ChangeLogHistory performMining(Properties configurationKnowledge) throws Exception{
		
		if(side == MergeSide.SOURCE){
			return createChangeLogsOfSource();
		}else{
			return createChangeLogsOfTarget();
		}
		
	}

	/**
	 * Create the set of simple evolution as the "ABC" exemple on Source system
	 * @param feature
	 */
	public ChangeLogHistory createChangeLogsOfSource( ) {
		
		ChangeLogHistory changeLogHistory = new ChangeLogHistory();
		

		changeLogHistory.setBaseVersion("1.0.0");
		changeLogHistory.setStartVersion("2.0.0");
		changeLogHistory.setSystem("mock");
		
		FeatureChangeLog featureCore = ChangeLogHistory.createNewCoreFeature();
		
		
		ChangeLog changeLog = new ChangeLog();
		
		changeLog.setIdentify(String.valueOf(1234560) );
		changeLog.setDescription( "Creating mock evolutions " );
		changeLog.setType(ChangeLogType.NEW_USE_CASE);
		
		changeLog.setVersion("1.5.0");
		changeLog.setChangeInformation("A Change Log created for tests");
		
		ClassChangeLog _classC = new ClassChangeLog("C.java", "Source/src/br/ufrn/example/C.java", "src/br/ufrn/example/C.java", ChangeTypeRepository.UPDATED, "123");
		_classC.addFieldChangeLog(new FieldChangeLog("cF", "int#cF", ChangeTypeRepository.ADDED));

		ClassChangeLog _classB = new ClassChangeLog("B.java", "Source/src/br/ufrn/example/B.java", "src/br/ufrn/example/B.java", ChangeTypeRepository.UPDATED, "123");
		_classB.addMethodChangeLog(new MethodChangeLog("b1", "int#b1(int,int)", ChangeTypeRepository.UPDATED));
		_classB.addMethodChangeLog(new MethodChangeLog("b2", "int#b2(int,int)", ChangeTypeRepository.UPDATED));
		_classB.addFieldChangeLog(new FieldChangeLog("b", "int:b", ChangeTypeRepository.UPDATED));
		
		ClassChangeLog _classD = new ClassChangeLog("D.java", "Source/src/br/ufrn/example/D.java", "src/br/ufrn/example/D.java", ChangeTypeRepository.ADDED, "123");
		_classD.addMethodChangeLog(new MethodChangeLog("d1", "double#d1(double,double)", ChangeTypeRepository.ADDED));
		
		// direct conflict
		ClassChangeLog _classF = new ClassChangeLog("F.java", "Source/src/br/ufrn/example/F.java", "src/br/ufrn/example/F.java", ChangeTypeRepository.UPDATED, "123");
		_classF.addMethodChangeLog(new MethodChangeLog("f1", "double#f1(double)", ChangeTypeRepository.UPDATED));
		_classF.addFieldChangeLog(new FieldChangeLog("f1", "int#f1", ChangeTypeRepository.DELETE));
		
		
		ChangeLog changeLog2 = new ChangeLog();
		
		changeLog2.setIdentify(String.valueOf(1234561) );
		changeLog2.setDescription( "Evolution in Pattern Variation Point" );
		changeLog2.setType(ChangeLogType.UPGRADING);
		
		changeLog2.setVersion("1.5.0");
		changeLog2.setChangeInformation("Evolution in variation point");
		
		// direct conflict in variation point
		ClassChangeLog _classG = new ClassChangeLog("G1.java", "Source/src/br/ufrn/example/G1.java", "src/br/ufrn/example/G1.java", ChangeTypeRepository.UPDATED, "Changed G1 implementation");
		_classG.addMethodChangeLog(new MethodChangeLog("g2", "void#g2()", ChangeTypeRepository.UPDATED));
		
		
		ChangeLog changeLog3 = new ChangeLog();
		
		changeLog3.setIdentify(String.valueOf(1234561) );
		changeLog3.setDescription( "Evolution Update" );
		changeLog3.setType(ChangeLogType.UPGRADING);
		
		changeLog3.setVersion("1.5.0");
		changeLog3.setChangeInformation("Evolution in conditional execution in target");
		
		// direct conflict in variation point
		ClassChangeLog _classH = new ClassChangeLog("H.java", "Source/src/br/ufrn/example/H.java", "src/br/ufrn/example/H.java", ChangeTypeRepository.UPDATED, "123");
		_classH.addMethodChangeLog(new MethodChangeLog("h1", "void#h1()", ChangeTypeRepository.UPDATED));
		
		
		changeLog.addClassChangeLog(_classB);
		changeLog.addClassChangeLog(_classC);
		changeLog.addClassChangeLog(_classD);
		changeLog.addClassChangeLog(_classF);
		
		changeLog2.addClassChangeLog(_classG);
		
		changeLog3.addClassChangeLog(_classH);
		
		featureCore.addChangeLog(changeLog);
		featureCore.addChangeLog(changeLog2);
		featureCore.addChangeLog(changeLog3);
		
		changeLogHistory.addFeature(featureCore);
		
		return changeLogHistory;
		
	}
	
	/**
	 * Create the set of simple evolution as the "ABC" exemple on Target system
	 * @param feature
	 */
	public ChangeLogHistory createChangeLogsOfTarget() {
		
		ChangeLogHistory changeLogHistory = new ChangeLogHistory();
		

		changeLogHistory.setBaseVersion("1.0.0");
		changeLogHistory.setStartVersion("2.0.0");
		changeLogHistory.setSystem("mock");
		
		FeatureChangeLog featureCore = ChangeLogHistory.createNewCoreFeature();
		
		ChangeLog changeLog = new ChangeLog();
		
		changeLog.setIdentify(String.valueOf(1234560) );
		changeLog.setDescription( "Creating mock evolutions " );
		changeLog.setType(ChangeLogType.NEW_USE_CASE);
		
		changeLog.setVersion("1.5.0");
		changeLog.setChangeInformation("A Change Log created for tests");
		
		ClassChangeLog _classC = new ClassChangeLog("C.java", "Target/src/br/ufrn/example/C.java", "src/exemple/C.java", ChangeTypeRepository.UPDATED, "123");
		_classC.addMethodChangeLog(new MethodChangeLog("c1", "int#c1(double,float)", ChangeTypeRepository.DELETE));
		_classC.addMethodChangeLog(new MethodChangeLog("c2", "int#c2()", ChangeTypeRepository.UPDATED));
		
		// direct conflict
		ClassChangeLog _classB = new ClassChangeLog("B.java", "Source/src/br/ufrn/example/B.java", "src/exemple/B.java", ChangeTypeRepository.UPDATED, "123");
		_classB.addMethodChangeLog(new MethodChangeLog("b1", "int#b1(int,int)", ChangeTypeRepository.UPDATED));
		
		ClassChangeLog _classE = new ClassChangeLog("E.java", "Target/src/br/ufrn/example/E.java", "src/exemple/E.java", ChangeTypeRepository.ADDED, "123");
		_classE.addMethodChangeLog(new MethodChangeLog("e1", "double#e1(double)", ChangeTypeRepository.ADDED));
		
		// direct conflict
		ClassChangeLog _classF = new ClassChangeLog("F.java", "Target/src/br/ufrn/example/F.java", "src/exemple/F.java", ChangeTypeRepository.UPDATED, "123");
		_classF.addMethodChangeLog(new MethodChangeLog("f1", "double#f1(double)", ChangeTypeRepository.UPDATED));
		
		
		ChangeLog changeLog2 = new ChangeLog();
		
		changeLog2.setIdentify(String.valueOf(1234561) );
		changeLog2.setDescription( "Evolution in variation point in target" );
		changeLog2.setType(ChangeLogType.UPGRADING);
		
		changeLog2.setVersion("1.5.0");
		changeLog2.setChangeInformation("Evolution in variation point in target");
		
		// direct conflict in variation point
		ClassChangeLog _classG = new ClassChangeLog("G1.java", "Target/src/br/ufrn/example/G1.java", "src/br/ufrn/example/G1.java", ChangeTypeRepository.UPDATED, "123");
		_classG.addMethodChangeLog(new MethodChangeLog("g2", "void#g2()", ChangeTypeRepository.UPDATED));
		
		
		
		ChangeLog changeLog3 = new ChangeLog();
		
		changeLog3.setIdentify(String.valueOf(1234561) );
		changeLog3.setDescription( "Evolution Update" );
		changeLog3.setType(ChangeLogType.UPGRADING);
		
		changeLog3.setVersion("1.5.0");
		changeLog3.setChangeInformation("Evolution in conditional execution in target");
		
		// direct conflict in variation point
		ClassChangeLog _classH = new ClassChangeLog("H.java", "Target/src/br/ufrn/example/H.java", "src/br/ufrn/example/H.java", ChangeTypeRepository.UPDATED, "123");
		_classH.addMethodChangeLog(new MethodChangeLog("h1", "void#h1()", ChangeTypeRepository.UPDATED));
		
		changeLog.addClassChangeLog(_classB);
		changeLog.addClassChangeLog(_classC);
		changeLog.addClassChangeLog(_classE);
		changeLog.addClassChangeLog(_classF);
		
		changeLog2.addClassChangeLog(_classG);
		
		changeLog3.addClassChangeLog(_classH);
		
		featureCore.addChangeLog(changeLog);
		featureCore.addChangeLog(changeLog2);
		featureCore.addChangeLog(changeLog3);
		
		changeLogHistory.addFeature(featureCore);
		
		return changeLogHistory;
	}

	
}
